/* 
 * File:   DescriptorReader.cpp
 * Author: max
 *
 * Created on Apr 4, 2013, 12:51:18 AM
 */

#include <stdlib.h>
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
#include "DescriptorReader.h"

using namespace std;
using namespace TP3::Mangling;

/*
 * Simple C++ Test Suite
 */

void test1() {
    std::cout << "DescriptorReader test 1" << std::endl;
    
    std::stringstream text;
    text.str("uppercase 1 2; Lowercase 3 4;");
    
    DescriptorReader reader (';');
    text >> reader;
    text >> reader;
    
    cout << reader.getName() << endl;
    
    for (int x = 0; x < reader.getCntParameters(); x++)
        cout << reader.getParameters()[x] << endl;
    
    cout << reader.getCntParameters() << endl;
    
    if (reader.getName() != "Lowercase" ||reader.getParameters()[0]!= "3" || reader.getParameters()[1] != "4")
    {
        std::cout << "%TEST_FAILED% time=0 testname=test1 (DescriptorReader) message=The reader is not showing the correct rule name.  uppercase expected an obteined " << reader.getName() << std::endl;
    }
}

void test2() {
    std::cout << "DescriptorReader test 2" << std::endl;
    
    ifstream input;
    
    input.open("/home/maximiliano/FIUBA/75.42.TP3.2013.1/Tests/E1/reglas.txt");
    
    if (input.is_open())
    {
        TP3::Mangling::DescriptorReader reader (';');
        
        while (! input.eof())
        {
            input >> reader;
            cout << reader.toString() << endl;
        }
        
        delete input;
    }
    else
    {
        std::cout << "%TEST_FAILED% time=0 testname=test2 (DescriptorReader) message=No se puede abrir el archivo de reglas." << std::endl;
    } 
    
}

int main(int argc, char** argv) {
    std::cout << "%SUITE_STARTING% DescriptorReader" << std::endl;
    std::cout << "%SUITE_STARTED%" << std::endl;

    std::cout << "%TEST_STARTED% test1 (DescriptorReader)" << std::endl;
    test1();
    std::cout << "%TEST_FINISHED% time=0 test1 (DescriptorReader)" << std::endl;
    
    std::cout << "%TEST_STARTED% test2 (DescriptorReader)\n" << std::endl;
    test2();
    std::cout << "%TEST_FINISHED% time=0 test2 (DescriptorReader)" << std::endl;
    
    std::cout << "%SUITE_FINISHED% time=0" << std::endl;

    return (EXIT_SUCCESS);
}

